/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * HoofdPagina.java
 *
 * Created on 17-mrt-2011, 11:29:06
 */
package view;

import connections.Query;
import java.awt.Color;
import javax.swing.JOptionPane;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;
import main.ApplicatieMain;

/**
 *
 * @author Jeroen
 */
public class WoordenlijstBeheer extends javax.swing.JPanel {

    private ApplicatieMain applicatieMain;
    private Query query;

    /** Creates new form HoofdPagina */
    public WoordenlijstBeheer() {
        applicatieMain = ApplicatieMain.getInstance();
        query = applicatieMain.getQuery();

        initComponents();
        
        updateWoordenLijst();

        ListSelectionListener listener1 = new ListSelectionListener() {

            public void valueChanged(ListSelectionEvent e) {
                updateWoorden();
                if(tblWoordenlijst.getSelectedRow()!=-1){
                    updateWoorden();
                    if(query.isDefaultWordList(Integer.parseInt(tblWoordenlijst.getValueAt(tblWoordenlijst.getSelectedRow(), 0).toString()))){
                        btnRemoveWoordenlijst.setEnabled(false);
                        btnEditWoordenLijst.setEnabled(false);
                        btnEditWord.setEnabled(false);
                        tblWoorden.setEnabled(false);
                    }
                    else{
                        btnRemoveWoordenlijst.setEnabled(true);
                        btnEditWoordenLijst.setEnabled(true);
                        btnEditWord.setEnabled(true);
                        tblWoorden.setEnabled(true);
                    }
                } else {
                    updateWoorden();
                    btnRemoveWoordenlijst.setEnabled(false);
                }
                
            }
        };
        tblWoordenlijst.getSelectionModel().addListSelectionListener(listener1);

        ListSelectionListener listener2 = new ListSelectionListener() {

            public void valueChanged(ListSelectionEvent e) {
                if(tblWoorden.getSelectedRow()!=-1){
                    if(query.isDefaultWordList(Integer.parseInt(tblWoordenlijst.getValueAt(tblWoordenlijst.getSelectedRow(), 0).toString()))){
                        btnDeleteWoord.setEnabled(false);
                    }
                    else{
                        btnDeleteWoord.setEnabled(true);
                    }
                } else {
                    btnDeleteWoord.setEnabled(false);
                }

            }
        };
        tblWoorden.getSelectionModel().addListSelectionListener(listener2);

        ChangeListener clistener = new ChangeListener() {
            public void stateChanged(ChangeEvent e) {
                if(Integer.parseInt(spinNiveau.getValue().toString()) > applicatieMain.getMax_niveau()){
                    spinNiveau.setValue(applicatieMain.getMax_niveau());
                }
                else if(Integer.parseInt(spinNiveau.getValue().toString()) < applicatieMain.getMin_niveau()){
                    spinNiveau.setValue(applicatieMain.getMin_niveau());
                }
            }
        };
        spinNiveau.addChangeListener(clistener);
        lblKlas.setText(query.getKlasName(applicatieMain.getSelectedKlasID()));

    }

    private void updateWoordenLijst(){

        DefaultTableModel model = (DefaultTableModel) tblWoordenlijst.getModel();
        model.setRowCount(0); // Clear table

        query.addWordListsToTable(tblWoordenlijst, applicatieMain.getSelectedKlasID()); // Add woordenlijsten
    }

    private void updateWoorden(){
        DefaultTableModel model = (DefaultTableModel) tblWoordenlijst.getModel();

        if(tblWoordenlijst.getSelectedRow() >= 0){
            int woordenlijstID = Integer.parseInt(model.getValueAt(tblWoordenlijst.getSelectedRow(), 0).toString());

            model = (DefaultTableModel) tblWoorden.getModel();
            model.setRowCount(0); // Clear table

            query.addWordsToTable(tblWoorden, woordenlijstID); // Add woordenlijsten
        }
        else{
            model = (DefaultTableModel) tblWoorden.getModel();
            model.setRowCount(0); // Clear table
        }
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel7 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblWoordenlijst = new javax.swing.JTable();
        btnAddWoordenlijst = new javax.swing.JButton();
        btnRemoveWoordenlijst = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        jScrollPane3 = new javax.swing.JScrollPane();
        tblWoorden = new javax.swing.JTable();
        btnAddWoord = new javax.swing.JButton();
        btnDeleteWoord = new javax.swing.JButton();
        btnEditWoordenLijst = new javax.swing.JButton();
        txtfieldWoord = new javax.swing.JTextField();
        spinNiveau = new javax.swing.JSpinner();
        lblWoord = new javax.swing.JLabel();
        lblNiveau = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        txtfieldBeschrijving = new javax.swing.JTextPane();
        jLabel3 = new javax.swing.JLabel();
        lblKlas = new javax.swing.JLabel();
        txtfieldWoordenlijstNaam = new javax.swing.JTextField();
        btnEditWord = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();

        setBackground(new java.awt.Color(255, 255, 255));
        setPreferredSize(new java.awt.Dimension(1074, 502));

        jPanel7.setBackground(new java.awt.Color(255, 255, 255));
        jPanel7.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(183, 234, 0), 10, true));

        tblWoordenlijst.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "ID", "Woordenlijsten"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, true
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tblWoordenlijst.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        tblWoordenlijst.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblWoordenlijstMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tblWoordenlijst);
        tblWoordenlijst.getColumnModel().getColumn(0).setResizable(false);
        tblWoordenlijst.getColumnModel().getColumn(0).setPreferredWidth(10);
        tblWoordenlijst.getColumnModel().getColumn(1).setResizable(false);
        tblWoordenlijst.getColumnModel().getColumn(1).setPreferredWidth(175);

        btnAddWoordenlijst.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/add.png"))); // NOI18N
        btnAddWoordenlijst.setText("Woordenlijst Toevoegen");
        btnAddWoordenlijst.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        btnAddWoordenlijst.setEnabled(false);
        btnAddWoordenlijst.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        btnAddWoordenlijst.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btnAddWoordenlijst.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddWoordenlijstActionPerformed(evt);
            }
        });

        btnRemoveWoordenlijst.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/delete.png"))); // NOI18N
        btnRemoveWoordenlijst.setText("Woordenlijst(en) verwijderen");
        btnRemoveWoordenlijst.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        btnRemoveWoordenlijst.setEnabled(false);
        btnRemoveWoordenlijst.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        btnRemoveWoordenlijst.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btnRemoveWoordenlijst.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRemoveWoordenlijstActionPerformed(evt);
            }
        });

        jSeparator1.setOrientation(javax.swing.SwingConstants.VERTICAL);

        tblWoorden.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "ID", "Woord", "Niveau", "Beschrijving"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Object.class, java.lang.String.class, java.lang.Object.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, true, true, true
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tblWoorden.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jScrollPane3.setViewportView(tblWoorden);
        tblWoorden.getColumnModel().getColumn(0).setResizable(false);
        tblWoorden.getColumnModel().getColumn(0).setPreferredWidth(50);
        tblWoorden.getColumnModel().getColumn(1).setMinWidth(50);
        tblWoorden.getColumnModel().getColumn(1).setPreferredWidth(150);
        tblWoorden.getColumnModel().getColumn(2).setResizable(false);
        tblWoorden.getColumnModel().getColumn(2).setPreferredWidth(50);
        tblWoorden.getColumnModel().getColumn(3).setMinWidth(50);
        tblWoorden.getColumnModel().getColumn(3).setPreferredWidth(300);

        btnAddWoord.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/add.png"))); // NOI18N
        btnAddWoord.setText("Woord Toevoegen");
        btnAddWoord.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        btnAddWoord.setEnabled(false);
        btnAddWoord.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        btnAddWoord.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btnAddWoord.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddWoordActionPerformed(evt);
            }
        });

        btnDeleteWoord.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/delete.png"))); // NOI18N
        btnDeleteWoord.setText("Woord(en) verwijderen");
        btnDeleteWoord.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        btnDeleteWoord.setEnabled(false);
        btnDeleteWoord.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        btnDeleteWoord.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btnDeleteWoord.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDeleteWoordActionPerformed(evt);
            }
        });

        btnEditWoordenLijst.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/toepassen.png"))); // NOI18N
        btnEditWoordenLijst.setText("Wijziging(en) toepassen");
        btnEditWoordenLijst.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        btnEditWoordenLijst.setEnabled(false);
        btnEditWoordenLijst.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        btnEditWoordenLijst.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btnEditWoordenLijst.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEditWoordenLijstActionPerformed(evt);
            }
        });

        txtfieldWoord.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtfieldWoordKeyTyped(evt);
            }
        });

        spinNiveau.setValue(5);

        lblWoord.setText("*Woord:");

        lblNiveau.setText("*Niveau:");

        jScrollPane2.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        jScrollPane2.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
        jScrollPane2.setViewportView(txtfieldBeschrijving);

        jLabel3.setText("Beschrijving:");

        lblKlas.setFont(new java.awt.Font("Tahoma", 0, 18));
        lblKlas.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lblKlas.setText("<UserCode>");

        txtfieldWoordenlijstNaam.setText("Woordenlijst naam");
        txtfieldWoordenlijstNaam.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtfieldWoordenlijstNaamActionPerformed(evt);
            }
        });
        txtfieldWoordenlijstNaam.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                txtfieldWoordenlijstNaamFocusGained(evt);
            }
        });
        txtfieldWoordenlijstNaam.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtfieldWoordenlijstNaamKeyTyped(evt);
            }
        });

        btnEditWord.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/toepassen.png"))); // NOI18N
        btnEditWord.setText("Wijziging(en) toepassen");
        btnEditWord.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        btnEditWord.setEnabled(false);
        btnEditWord.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        btnEditWord.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btnEditWord.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEditWordActionPerformed(evt);
            }
        });

        jButton1.setText("Terug");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 262, Short.MAX_VALUE)
                    .addComponent(lblKlas, javax.swing.GroupLayout.DEFAULT_SIZE, 262, Short.MAX_VALUE)
                    .addComponent(btnRemoveWoordenlijst, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 262, Short.MAX_VALUE)
                    .addComponent(txtfieldWoordenlijstNaam, javax.swing.GroupLayout.DEFAULT_SIZE, 262, Short.MAX_VALUE)
                    .addComponent(btnAddWoordenlijst, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 262, Short.MAX_VALUE)
                    .addComponent(btnEditWoordenLijst, javax.swing.GroupLayout.DEFAULT_SIZE, 262, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel7Layout.createSequentialGroup()
                                .addComponent(lblWoord)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtfieldWoord, javax.swing.GroupLayout.DEFAULT_SIZE, 224, Short.MAX_VALUE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(lblNiveau)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(spinNiveau, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, 368, Short.MAX_VALUE)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 368, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(btnDeleteWoord, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(btnAddWoord, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 167, Short.MAX_VALUE)
                            .addComponent(btnEditWord, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(12, 12, 12))
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 545, Short.MAX_VALUE)
                        .addContainerGap())))
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel7Layout.createSequentialGroup()
                                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(txtfieldWoord, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(lblWoord, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(spinNiveau, javax.swing.GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE)
                                        .addComponent(lblNiveau, javax.swing.GroupLayout.DEFAULT_SIZE, 21, Short.MAX_VALUE)))
                                .addGap(11, 11, 11))
                            .addGroup(jPanel7Layout.createSequentialGroup()
                                .addComponent(jButton1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnEditWord)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                        .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel7Layout.createSequentialGroup()
                                .addComponent(btnDeleteWoord)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnAddWoord))
                            .addGroup(jPanel7Layout.createSequentialGroup()
                                .addComponent(jLabel3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 427, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 549, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel7Layout.createSequentialGroup()
                        .addComponent(lblKlas, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnEditWoordenLijst, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnRemoveWoordenlijst)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtfieldWoordenlijstNaam, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnAddWoordenlijst)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 388, Short.MAX_VALUE)))
                .addContainerGap())
        );

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 1064, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 92, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 567, Short.MAX_VALUE)
        );

        jPanel3.setBackground(new java.awt.Color(255, 255, 255));

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 1058, Short.MAX_VALUE)
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );

        jPanel4.setBackground(new java.awt.Color(255, 255, 255));

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 93, Short.MAX_VALUE)
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 591, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void btnRemoveWoordenlijstActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoveWoordenlijstActionPerformed

        int rows[] = tblWoordenlijst.getSelectedRows();

        // Popup om te verwijderen
        Object[] options = { "Nee", "Ja"};
        int keuze = JOptionPane.showOptionDialog(null, "Weet u zeker dat u woordenlijst selectie \"" +
                tblWoordenlijst.getValueAt(rows[0],1) + "\" t/m \"" +
                tblWoordenlijst.getValueAt(rows[rows.length-1],1) + "\" wilt verwijderen", "Verwijderen?",
            JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE,
            null, options, options[0]);
       switch(keuze){
            default:{
                System.out.println("Unknown option in keuze OptionDialog");
                break;
            }
            case 0:{
                System.out.println("Woordenlijst niet gewist");
                break;
            }
            case 1:{
                if (tblWoordenlijst.getCellEditor() != null) {
                    tblWoordenlijst.getCellEditor().stopCellEditing();
                }
                if (tblWoorden.getCellEditor() != null) {
                        tblWoorden.getCellEditor().stopCellEditing();
                }
                for (int i : rows) {
                    query.deleteWordList(Integer.parseInt(tblWoordenlijst.getValueAt(i, 0).toString()));
                }
                updateWoorden();
                updateWoordenLijst();
                break;
            }
        }

    }//GEN-LAST:event_btnRemoveWoordenlijstActionPerformed

    private void tblWoordenlijstMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblWoordenlijstMouseClicked

    }//GEN-LAST:event_tblWoordenlijstMouseClicked

    private void btnAddWoordenlijstActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddWoordenlijstActionPerformed
        if(txtfieldWoordenlijstNaam.getText().isEmpty() || txtfieldWoordenlijstNaam.getText().equals("Woordenlijst naam")){
            txtfieldWoordenlijstNaam.setForeground(Color.red);
            JOptionPane.showConfirmDialog(null, "Niet alle velden zijn ingevuld.", "Woordenlijst Toevoegen",JOptionPane.DEFAULT_OPTION);
            txtfieldWoordenlijstNaam.setText("Woordenlijst naam");
        }
        else{
            if(query.wordListExists(applicatieMain.getSelectedKlasID(), txtfieldWoordenlijstNaam.getText()) != -1){ // Woord Bestaat
                JOptionPane.showConfirmDialog(null, "Er bestaat al een woordenlijst met de naam \"" + txtfieldWoordenlijstNaam.getText() + "\"",
                        "Woordenlijst Toevoegen", JOptionPane.DEFAULT_OPTION);
            }
            else{
                query.addWordList(applicatieMain.getSelectedKlasID(), txtfieldWoordenlijstNaam.getText());
                updateWoordenLijst();
                txtfieldWoordenlijstNaam.setForeground(Color.black);
                txtfieldWoordenlijstNaam.setText("Woordenlijst naam");
            }
        }
    }//GEN-LAST:event_btnAddWoordenlijstActionPerformed

    private void btnDeleteWoordActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeleteWoordActionPerformed
        int rows[] = tblWoorden.getSelectedRows();

        // Popup om te verwijderen
        Object[] options = { "Nee", "Ja"};
        int keuze = JOptionPane.showOptionDialog(null, "Weet u zeker dat u woorden selectie \"" +
                tblWoorden.getValueAt(rows[0], 1) + "\" t/m \"" +
                tblWoorden.getValueAt(rows[rows.length-1], 1) + "\" wilt verwijderen", "Verwijderen?",
            JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE,
            null, options, options[0]);
       switch(keuze){
            default:{
                System.out.println("Unknown option in keuze OptionDialog");
                break;
            }
            case 0:{
                System.out.println("Woorden niet gewist");
                break;
            }
            case 1:{
                if (tblWoorden.getCellEditor() != null) {
                    tblWoorden.getCellEditor().stopCellEditing();
                }
                for (int i : rows) {
                    query.deleteWord(Integer.parseInt(tblWoorden.getValueAt(i, 0).toString()));
                }
                updateWoorden();
                break;
            }
        }

    }//GEN-LAST:event_btnDeleteWoordActionPerformed

    private void btnEditWoordenLijstActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditWoordenLijstActionPerformed

        query.updateWordListByTable(tblWoordenlijst);
    }//GEN-LAST:event_btnEditWoordenLijstActionPerformed

    private void txtfieldWoordenlijstNaamFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtfieldWoordenlijstNaamFocusGained
        txtfieldWoordenlijstNaam.setText(null);
    }//GEN-LAST:event_txtfieldWoordenlijstNaamFocusGained

    private void btnEditWordActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditWordActionPerformed

        query.updateWordsByTable(tblWoorden);
    }//GEN-LAST:event_btnEditWordActionPerformed

    private void btnAddWoordActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddWoordActionPerformed
        if(txtfieldWoord.getText().isEmpty()){
            lblWoord.setForeground(Color.red);
            JOptionPane.showConfirmDialog(null, "Niet alle velden zijn ingevuld.", "Woord Toevoegen",JOptionPane.DEFAULT_OPTION);
        }
        else{
            if(tblWoordenlijst.getSelectedRow() == -1){
               JOptionPane.showConfirmDialog(null, "Er is geen woordenlijst geselecteerd.", "Woord Toevoegen",JOptionPane.DEFAULT_OPTION);
            }
            else{
                if(query.getWordID(txtfieldWoord.getText(), 
                        Integer.parseInt(tblWoordenlijst.getValueAt(tblWoordenlijst.getSelectedRow(), 0).toString())) != -1){ // Woord Bestaat
                    JOptionPane.showConfirmDialog(null, "\"" + txtfieldWoord.getText() + "\" bestaat al in de woordenlijst.", "Woord Toevoegen",JOptionPane.DEFAULT_OPTION);
                }
                else{
                    query.addWord(txtfieldWoord.getText(),
                        Integer.parseInt(spinNiveau.getValue().toString()),
                        txtfieldBeschrijving.getText(),
                        Integer.parseInt(tblWoordenlijst.getValueAt(tblWoordenlijst.getSelectedRow(), 0).toString()));

                    updateWoorden();
                    lblWoord.setForeground(Color.black);
                    txtfieldBeschrijving.setText(null);
                    txtfieldWoord.setText(null);
                    spinNiveau.setValue(5);
                }
            }

        }
    }//GEN-LAST:event_btnAddWoordActionPerformed

    private void txtfieldWoordenlijstNaamActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtfieldWoordenlijstNaamActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtfieldWoordenlijstNaamActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        applicatieMain.setSelectedKlasID(0);
        applicatieMain.showPage(new view.KlassenBeheerPagina());
    }//GEN-LAST:event_jButton1ActionPerformed

    private void txtfieldWoordenlijstNaamKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtfieldWoordenlijstNaamKeyTyped
        if(!txtfieldWoordenlijstNaam.getText().equals("")){
            btnAddWoordenlijst.setEnabled(true);
        } else {
            btnAddWoordenlijst.setEnabled(false);
        }
    }//GEN-LAST:event_txtfieldWoordenlijstNaamKeyTyped

    private void txtfieldWoordKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtfieldWoordKeyTyped
        if(!txtfieldWoord.getText().equals("")){
            btnAddWoord.setEnabled(true);
        } else {
            btnAddWoord.setEnabled(false);
        }
    }//GEN-LAST:event_txtfieldWoordKeyTyped

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAddWoord;
    private javax.swing.JButton btnAddWoordenlijst;
    private javax.swing.JButton btnDeleteWoord;
    private javax.swing.JButton btnEditWoordenLijst;
    private javax.swing.JButton btnEditWord;
    private javax.swing.JButton btnRemoveWoordenlijst;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JLabel lblKlas;
    private javax.swing.JLabel lblNiveau;
    private javax.swing.JLabel lblWoord;
    private javax.swing.JSpinner spinNiveau;
    private javax.swing.JTable tblWoorden;
    private javax.swing.JTable tblWoordenlijst;
    private javax.swing.JTextPane txtfieldBeschrijving;
    private javax.swing.JTextField txtfieldWoord;
    private javax.swing.JTextField txtfieldWoordenlijstNaam;
    // End of variables declaration//GEN-END:variables

}
